class FeedController < ApplicationController

  def index
    @feeds = Feed.find :all , :include => [:entries]
  end
  
  def new
    @feed = Feed.new
  end
  
  def create
    @feed = Feed.new params[:feed]
    if xml = Feed.is_feed? (@feed.url , :feed_url)
      @feed.parse_feed xml , :feed_url
      if @feed.save
         redirect_to :action => 'index'
      else
         flash[:notice]='The feed has no saved. Please check de fields'
         render :action => 'new'
      end
    else
       flash[:notice]='The feed has no saved. Invalid URL'
         render :action => 'new'  
    end  
  end
  
  
  def show_entries
    @feed = Feed.find params[:id] , :include => [:entries]
  end
  
  
  def update_entries
    @feed = Feed.find params[:id]
    @feed.get_entries :update
    render :action => 'show_entries'
  end
  
  
  def destroy
    Feed.find params[:id].destroy
    redirect _to :action => 'index'
  end


end